from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-05 14:03:59.297618
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 05, Jan, 2022
Time: 14:04:05
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6192
Nobs: 527.000 HQIC: -48.0626
Log likelihood: 6099.65 FPE: 1.00643e-21
AIC: -48.3479 Det(Omega_mle): 8.49791e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.373706 0.075806 4.930 0.000
L1.Burgenland 0.099034 0.043134 2.296 0.022
L1.Kärnten -0.113803 0.022191 -5.128 0.000
L1.Niederösterreich 0.174563 0.089616 1.948 0.051
L1.Oberösterreich 0.103455 0.089429 1.157 0.247
L1.Salzburg 0.279193 0.045981 6.072 0.000
L1.Steiermark 0.030141 0.059887 0.503 0.615
L1.Tirol 0.109287 0.048234 2.266 0.023
L1.Vorarlberg -0.077813 0.042681 -1.823 0.068
L1.Wien 0.028130 0.080377 0.350 0.726
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.041391 0.166915 0.248 0.804
L1.Burgenland -0.043161 0.094975 -0.454 0.650
L1.Kärnten 0.039849 0.048863 0.816 0.415
L1.Niederösterreich -0.208946 0.197323 -1.059 0.290
L1.Oberösterreich 0.457732 0.196913 2.325 0.020
L1.Salzburg 0.293574 0.101245 2.900 0.004
L1.Steiermark 0.116301 0.131863 0.882 0.378
L1.Tirol 0.306844 0.106206 2.889 0.004
L1.Vorarlberg 0.018046 0.093979 0.192 0.848
L1.Wien -0.012384 0.176980 -0.070 0.944
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.205111 0.038806 5.286 0.000
L1.Burgenland 0.092688 0.022081 4.198 0.000
L1.Kärnten -0.007334 0.011360 -0.646 0.519
L1.Niederösterreich 0.231179 0.045876 5.039 0.000
L1.Oberösterreich 0.160202 0.045781 3.499 0.000
L1.Salzburg 0.041777 0.023539 1.775 0.076
L1.Steiermark 0.025990 0.030657 0.848 0.397
L1.Tirol 0.083267 0.024692 3.372 0.001
L1.Vorarlberg 0.054492 0.021849 2.494 0.013
L1.Wien 0.113986 0.041146 2.770 0.006
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.140238 0.038810 3.613 0.000
L1.Burgenland 0.040330 0.022083 1.826 0.068
L1.Kärnten -0.014662 0.011361 -1.291 0.197
L1.Niederösterreich 0.164913 0.045880 3.594 0.000
L1.Oberösterreich 0.334113 0.045785 7.297 0.000
L1.Salzburg 0.104734 0.023541 4.449 0.000
L1.Steiermark 0.108416 0.030660 3.536 0.000
L1.Tirol 0.093892 0.024694 3.802 0.000
L1.Vorarlberg 0.053679 0.021851 2.457 0.014
L1.Wien -0.026382 0.041150 -0.641 0.521
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.087643 0.073836 1.187 0.235
L1.Burgenland -0.043400 0.042013 -1.033 0.302
L1.Kärnten -0.046136 0.021615 -2.134 0.033
L1.Niederösterreich 0.147290 0.087287 1.687 0.092
L1.Oberösterreich 0.175908 0.087106 2.019 0.043
L1.Salzburg 0.283613 0.044786 6.333 0.000
L1.Steiermark 0.062930 0.058331 1.079 0.281
L1.Tirol 0.154434 0.046981 3.287 0.001
L1.Vorarlberg 0.092958 0.041572 2.236 0.025
L1.Wien 0.088883 0.078288 1.135 0.256
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.083182 0.057184 1.455 0.146
L1.Burgenland 0.017609 0.032538 0.541 0.588
L1.Kärnten 0.051851 0.016740 3.097 0.002
L1.Niederösterreich 0.185190 0.067601 2.739 0.006
L1.Oberösterreich 0.327665 0.067461 4.857 0.000
L1.Salzburg 0.045769 0.034686 1.320 0.187
L1.Steiermark -0.002307 0.045175 -0.051 0.959
L1.Tirol 0.126122 0.036385 3.466 0.001
L1.Vorarlberg 0.062110 0.032196 1.929 0.054
L1.Wien 0.103958 0.060632 1.715 0.086
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.148802 0.069514 2.141 0.032
L1.Burgenland 0.009892 0.039554 0.250 0.803
L1.Kärnten -0.065400 0.020350 -3.214 0.001
L1.Niederösterreich -0.107700 0.082178 -1.311 0.190
L1.Oberösterreich 0.220066 0.082007 2.683 0.007
L1.Salzburg 0.052727 0.042165 1.250 0.211
L1.Steiermark 0.254101 0.054916 4.627 0.000
L1.Tirol 0.497961 0.044231 11.258 0.000
L1.Vorarlberg 0.065389 0.039139 1.671 0.095
L1.Wien -0.071837 0.073706 -0.975 0.330
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.143789 0.076691 1.875 0.061
L1.Burgenland -0.009814 0.043637 -0.225 0.822
L1.Kärnten 0.063448 0.022451 2.826 0.005
L1.Niederösterreich 0.175438 0.090662 1.935 0.053
L1.Oberösterreich -0.071112 0.090474 -0.786 0.432
L1.Salzburg 0.217382 0.046518 4.673 0.000
L1.Steiermark 0.139895 0.060586 2.309 0.021
L1.Tirol 0.053886 0.048797 1.104 0.269
L1.Vorarlberg 0.144299 0.043179 3.342 0.001
L1.Wien 0.145597 0.081315 1.791 0.073
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.425063 0.044622 9.526 0.000
L1.Burgenland -0.004666 0.025390 -0.184 0.854
L1.Kärnten -0.020760 0.013063 -1.589 0.112
L1.Niederösterreich 0.193360 0.052752 3.665 0.000
L1.Oberösterreich 0.233738 0.052642 4.440 0.000
L1.Salzburg 0.037911 0.027066 1.401 0.161
L1.Steiermark -0.020118 0.035252 -0.571 0.568
L1.Tirol 0.090387 0.028393 3.183 0.001
L1.Vorarlberg 0.047903 0.025124 1.907 0.057
L1.Wien 0.020365 0.047313 0.430 0.667
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.029932 0.089299 0.157287 0.134124 0.073233 0.076619 0.015903 0.200423
Kärnten 0.029932 1.000000 -0.030793 0.131576 0.045885 0.079483 0.446623 -0.075175 0.092233
Niederösterreich 0.089299 -0.030793 1.000000 0.303903 0.123731 0.258426 0.059823 0.148408 0.271074
Oberösterreich 0.157287 0.131576 0.303903 1.000000 0.216150 0.288099 0.166233 0.130668 0.221352
Salzburg 0.134124 0.045885 0.123731 0.216150 1.000000 0.121897 0.077407 0.106381 0.125418
Steiermark 0.073233 0.079483 0.258426 0.288099 0.121897 1.000000 0.129553 0.093971 0.016430
Tirol 0.076619 0.446623 0.059823 0.166233 0.077407 0.129553 1.000000 0.059215 0.145863
Vorarlberg 0.015903 -0.075175 0.148408 0.130668 0.106381 0.093971 0.059215 1.000000 -0.012946
Wien 0.200423 0.092233 0.271074 0.221352 0.125418 0.016430 0.145863 -0.012946 1.000000